package com.axt.dbaudit.action.query.report;

import java.util.List;

import org.apache.struts2.json.annotations.JSON;

import com.axt.dbaudit.action.query.QueryBaseAction;
import com.axt.dbaudit.bean.query.report.QueryReportFlowBean;
import com.axt.dbaudit.model.query.report.FlowByClientIp;
import com.axt.dbaudit.model.query.report.FlowByClientIpSort;
import com.axt.dbaudit.model.query.report.FlowByTime;
import com.axt.soa.msg.types.MsgParam;

public class QueryReportFlowAction extends QueryBaseAction{
	private QueryReportFlowBean queryReportFlowBean = new QueryReportFlowBean();
	private List<FlowByTime> flowByTimes = null;
	private List<FlowByClientIp> flowByClientIps = null;
	private List<FlowByClientIpSort> flowByClientIpSorts = null;
	
	@JSON(name="flowbytimes")
	public List<FlowByTime> getFlowByTimes() {
		return flowByTimes;
	}
	
	void setFlowByTimes(List<FlowByTime> flowByTimes) {
		this.flowByTimes = flowByTimes;
	}
	
	@JSON(name="flowbyclientips")
	public List<FlowByClientIp> flowByClientIps() {
		return flowByClientIps;
	}
	
	void setFlowByClientIp(List<FlowByClientIp> flowByClientIps) {
		this.flowByClientIps = flowByClientIps;
	}
	
	@JSON(name="flowbyclientipsort")
	public List<FlowByClientIpSort> getFlowByClientIpSorts() {
		return flowByClientIpSorts;
	}
	
	void setFlowByClientIpSort(List<FlowByClientIpSort> flowByClientIpSorts) {
		this.flowByClientIpSorts = flowByClientIpSorts;
	}
	
	/* 停止查询 */
	public String stopQuery() {
		
		/* 停止查询索引 */
		queryReportFlowBean.stopQueryIndices(serverPath);
		
		setErrcode(queryReportFlowBean.getErrcode());
		setErrinfo(queryReportFlowBean.getErrinfo());
		
		return MsgParam.SUCCESS;

	}
	
	/* 按时间统计流量 发请求 */
	public String statFlowByTimeRgn() {
		
		/* 查询索引 */
		queryReportFlowBean.StatForFlowsByTimeRgn(serverPath, filters, maxRowNum);
		
		setErrcode(queryReportFlowBean.getErrcode());
		setErrinfo(queryReportFlowBean.getErrinfo());
		
		return MsgParam.SUCCESS;

	}
	
	/* 按时间统计流量 取结果 */
	public String statFlowByTimeRgnData() {
		
		/* 查询数据 */
		queryReportFlowBean.StatForFlowsByTimeRgnData(serverPath, filters, maxRowNum);
		
		setFlowByTimes(queryReportFlowBean.getFlowByTimes());
		setErrcode(queryReportFlowBean.getErrcode());
		setErrinfo(queryReportFlowBean.getErrinfo());
		
		return MsgParam.SUCCESS;

	}
	
	// 流量统计报表 根据客户端IP统计 查索引
	public String StatForFlowsByCliIP() {
		
		/* 查询索引 */
		queryReportFlowBean.StatForFlowsByCliIP(serverPath, filters, maxRowNum);
		
		setErrcode(queryReportFlowBean.getErrcode());
		setErrinfo(queryReportFlowBean.getErrinfo());
		
		return MsgParam.SUCCESS;

	}
	
	/* 按时间统计流量 取结果 */
	public String StatForFlowsByCliIPData() {
		
		/* 查询数据 */
		queryReportFlowBean.StatForFlowsByCliIPData(serverPath, filters, maxRowNum);
		
		setFlowByClientIp(queryReportFlowBean.getFlowByClientIps());
		setErrcode(queryReportFlowBean.getErrcode());
		setErrinfo(queryReportFlowBean.getErrinfo());
		
		return MsgParam.SUCCESS;

	}
	
	// 流量统计报表 根据客户端IP排序 -1是根据全部流量排
	public String SortForFlowsByCliIP() {
		
		queryReportFlowBean.SortForFlowsByCliIP(serverPath, filters, maxRowNum);
		
		setErrcode(queryReportFlowBean.getErrcode());
		setErrinfo(queryReportFlowBean.getErrinfo());
		
		return MsgParam.SUCCESS;
	}

	// 流量统计报表 根据客户端IP排序 -1是根据全部流量排
	public String SortForFlowsByCliIPData() {
		
		queryReportFlowBean.SortForFlowsByCliIPData(serverPath, filters, maxRowNum);
		
		setFlowByClientIpSort(queryReportFlowBean.getFlowByClientIpSorts());
		setErrcode(queryReportFlowBean.getErrcode());
		setErrinfo(queryReportFlowBean.getErrinfo());
		
		return MsgParam.SUCCESS;	
	}
	
	// 流量统计报表 根据客户端IP排序,  0是根据客户端流量排，1是根据服务器流量排
	public String SortForFlowsByCliIPSvrFlow() {
		
		queryReportFlowBean.SortForFlowsByCliIPSvrFlow(serverPath, filters, maxRowNum);
		
		setErrcode(queryReportFlowBean.getErrcode());
		setErrinfo(queryReportFlowBean.getErrinfo());
		
		return MsgParam.SUCCESS;
	}

	// 流量统计报表 根据客户端IP排序 ，0是根据客户端流量排，1是根据服务器流量排
	public String SortForFlowsByCliIPSvrFlowData() {
		
		queryReportFlowBean.SortForFlowsByCliIPSvrFlowData(serverPath, filters, maxRowNum);
		
		setFlowByClientIpSort(queryReportFlowBean.getFlowByClientIpSorts());
		setErrcode(queryReportFlowBean.getErrcode());
		setErrinfo(queryReportFlowBean.getErrinfo());
		
		return MsgParam.SUCCESS;
	}
	
	// 流量统计报表 根据客户端IP排序,  0是根据客户端流量排，1是根据服务器流量排
	public String SortForFlowsByCliIPCliFlow() {
		
		queryReportFlowBean.SortForFlowsByCliIPCliFlow(serverPath, filters, maxRowNum);
		
		setErrcode(queryReportFlowBean.getErrcode());
		setErrinfo(queryReportFlowBean.getErrinfo());
		
		return MsgParam.SUCCESS;
	}

	// 流量统计报表 根据客户端IP排序 ，0是根据客户端流量排，1是根据服务器流量排
	public String SortForFlowsByCliIPCliFlowData() {
		
		queryReportFlowBean.SortForFlowsByCliIPCliFlowData(serverPath, filters, maxRowNum);
		
		setFlowByClientIpSort(queryReportFlowBean.getFlowByClientIpSorts());
		setErrcode(queryReportFlowBean.getErrcode());
		setErrinfo(queryReportFlowBean.getErrinfo());
		
		return MsgParam.SUCCESS;
	}
}
